/*
 *   This file is part of <open-parametrics>
 *   Copyright (c) 2006-2008 Miguel-Angel Sicilia
 *
 *   open-parametrics is free software: you can redistribute it and/or modify
 *   it under the terms of the Lesser GNU General Public License as
 *   published by the Free Software Foundation, either version 3 of
 *   the License, or (at your option) any later version.
 *
 *   open-parametrics is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with open-parametrics.  If not, see <http://www.gnu.org/licenses/>.
 */

package es.uah.cc.ie.parametrics.regress;

import es.uah.cc.ie.parametrics.CostDriverValue;
import es.uah.cc.ie.parametrics.CostEstimatingRelationship;
import java.util.List;
import org.apache.commons.math.stat.regression.SimpleRegression;


/**
 *
 * @author Miguel-Angel Sicilia
 */
public class SimpleSingleLinearRegressionCER extends CostEstimatingRelationship {

     private SimpleRegression _model;

    public SimpleSingleLinearRegressionCER(String label,
                                           SimpleRegression model){
        super(label); _model= model;
    }
    
    /**

     *
     * @param instance The concrete case for which the estimation is desired.
     * @return An estimation of effort in man-months.
     */
    @Override
    public double estimate(List<CostDriverValue> instance) {
       assert(instance.size()==1);
       CostDriverValue cdv = (CostDriverValue)instance.get(0);
       return _model.predict(cdv.getValue());
    }

    /**
     * Returns Pearson's product moment correlation coefficient, 
     * usually denoted R. R lies in [-1, +1] with zero representing
     * non-linear relationship.
     * @return
     */
    public double getR(){
        return _model.getR();
    }
 }
